package com.shuai.utils.returnVo;

import com.shuai.enums.SystemEnum;
import lombok.*;

/**
 * 返回数据格式
 *
 * @author shuai.zhao
 * @since 2022
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class ReturnModel<T> {
    /**
     * 返回状态码
     */
    private String code;
    /**
     * 返回信息
     */
    private String message;
    /**
     * 返回数据
     */
    private T data;
    /**
     * 返回状态
     */
    private boolean success;


    private ReturnModel(String code, String msg) {
        this.code = code;
        this.message = msg;
    }

    private ReturnModel(String code, String msg, T data) {
        this.code = code;
        this.message = msg;
        this.data = data;
    }

    public static <T>ReturnModel<T> successInstance() {
        ReturnModel<T> returnModel = new ReturnModel(SystemEnum.T200.getCode(), SystemEnum.T200.getMsg());
        returnModel.setSuccess(true);
        return returnModel;
    }


    public static <T> ReturnModel<T> successInstance(T data) {
        ReturnModel<T> returnModel = new ReturnModel(SystemEnum.T200.getCode(), SystemEnum.T200.getMsg(), data);
        returnModel.setSuccess(true);
        return returnModel;
    }

    public static <T> ReturnModel<T> successInstance(SystemEnum modelEnum) {
        ReturnModel<T> returnModel = new ReturnModel(modelEnum.getCode(), modelEnum.getMsg());
        returnModel.setSuccess(true);
        return returnModel;
    }

    public static <T> ReturnModel<T> successInstance(SystemEnum modelEnum, T data) {
        ReturnModel<T> returnModel = new ReturnModel(modelEnum.getCode(), modelEnum.getMsg(), data);
        returnModel.setSuccess(true);
        return returnModel;
    }

    public static <T> ReturnModel<T> successInstance(String code, String msg, T data) {
        ReturnModel<T> returnModel = new ReturnModel(code, msg, data);
        returnModel.setSuccess(true);
        return returnModel;
    }

    public static <T> ReturnModel<T> failureInstance() {
        ReturnModel<T> returnModel = new ReturnModel(SystemEnum.F400.getCode(), SystemEnum.F400.getMsg());
        returnModel.setSuccess(false);
        return returnModel;
    }

    public static <T> ReturnModel<T> failureInstance(T data) {
        ReturnModel<T> returnModel = new ReturnModel(SystemEnum.F400.getCode(), SystemEnum.F400.getMsg(), data);
        returnModel.setSuccess(false);
        return returnModel;
    }

    public static <T> ReturnModel<T> failureInstance(SystemEnum modelEnum) {
        ReturnModel<T> returnModel = new ReturnModel(modelEnum.getCode(), modelEnum.getMsg());
        returnModel.setSuccess(false);
        return returnModel;
    }

    public static <T> ReturnModel<T> failureInstance(SystemEnum modelEnum, T data) {
        ReturnModel<T> returnModel = new ReturnModel(modelEnum.getCode(), modelEnum.getMsg(), data);
        returnModel.setSuccess(false);
        return returnModel;
    }

    public static <T> ReturnModel<T> failureInstance(String code, String msg, T data) {
        ReturnModel<T> returnModel = new ReturnModel(code, msg, data);
        returnModel.setSuccess(false);
        return returnModel;
    }

    public static <T> ReturnModel<T> failureInstance(String code, String msg) {
        ReturnModel<T> returnModel = new ReturnModel(code, msg);
        returnModel.setSuccess(false);
        return returnModel;
    }
}
